popover: Update child visibility when scrolling happens
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 22 Jan 2014 15:45:01 +0000 (16:45 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 22 Jan 2014 16:10:07 +0000 (17:10 +0100)
If pointing_to starts falling outside of the parent scrollable allocation,
the popover will be automatically hidden, and shown back again when
pointing_to scrolls back to visibility.

gtk/gtkpopover.c

index 5d25b4f5d9a63dfd6fd531b026ff304123a94e13..f055dcdb8ac3306777bcda13a2a34e73bb0a5a6f 100644 (file)
@@ -599,6 +599,37 @@ gtk_popover_update_shape (GtkPopover *popover)
   cairo_region_destroy (region);
 }
 
+static void
+_gtk_popover_update_child_visible (GtkPopover *popover)
+{
+  cairo_rectangle_int_t rect;
+  GtkAllocation allocation;
+  GtkPopoverPrivate *priv;
+  GtkWidget *parent;
+
+  priv = popover->priv;
+
+  if (!priv->parent_scrollable)
+    {
+      gtk_widget_set_child_visible (GTK_WIDGET (popover), TRUE);
+      return;
+    }
+
+  parent = gtk_widget_get_parent (GTK_WIDGET (priv->parent_scrollable));
+  rect = priv->pointing_to;
+
+  gtk_widget_translate_coordinates (priv->widget, parent,
+                                    rect.x, rect.y, &rect.x, &rect.y);
+
+  gtk_widget_get_allocation (GTK_WIDGET (parent), &allocation);
+
+  if (rect.x < 0 || rect.x + rect.width > allocation.width ||
+      rect.y < 0 || rect.y + rect.height > allocation.height)
+    gtk_widget_set_child_visible (GTK_WIDGET (popover), FALSE);
+  else
+    gtk_widget_set_child_visible (GTK_WIDGET (popover), TRUE);
+}
+
 static void
 gtk_popover_update_position (GtkPopover *popover)
 {
@@ -642,6 +673,8 @@ gtk_popover_update_position (GtkPopover *popover)
 
       priv->current_position = priv->final_position;
     }
+
+  _gtk_popover_update_child_visible (popover);
 }
 
 static gboolean